home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolf3dmacsource.sit / Wolf3DMacSource / WolfIO.c < prev    next >
C/C++ Source or Header  |  1994-10-06  |  6KB  |  262 lines

  1. #include "WolfDef.h"
  2. #include <string.h>
  3.  
  4. /**********************************
  5.  
  6.     Draw a space padded list of numbers 
  7.     for the score
  8.     
  9. **********************************/
  10.  
  11. LongWord pow10[] = {1,10,100,1000,10000,100000,1000000};
  12. Word NumberIndex = 36;        /* First number in the shape list... */
  13.  
  14. void SetNumber(LongWord number,Word x,Word y,Word digits)
  15. {
  16.     LongWord val;
  17.     Word count;
  18.     Word empty;
  19.     
  20.     empty = 1;            /* No char's drawn yet */
  21.     while (digits) {    /* Any digits left? */
  22.          count = 0;        /* No value yet */
  23.          val = pow10[digits-1];    /* Get the power of 10 */
  24.          while (number >= val) {    /* Any value here? */
  25.              count++;        /* +1 to the count */
  26.              number -= val;        /* Remove the value */
  27.          }
  28.          if (empty && !count && digits!=1) {    /* pad on left with blanks rather than 0 */
  29.               DrawShape(x,y,GameShapes[NumberIndex]);
  30.          } else {
  31.               empty = 0;        /* I have drawn... */
  32.               DrawShape(x,y,GameShapes[count+NumberIndex]);    /* Draw the digit */
  33.          }
  34.          x+=ScaleX(8);
  35.          digits--;        /* Count down */
  36.     }
  37. }
  38.  
  39. /**********************************
  40.  
  41.     Read from the Mac's keyboard/mouse system
  42.     
  43. **********************************/
  44.  
  45. void IO_CheckInput(void)
  46. {
  47.     ReadSystemJoystick();    /* Set the variable "joystick1" */
  48.     
  49. /* check for auto map */
  50.  
  51.     if (joystick1 & JOYPAD_START) {
  52.          RunAutoMap();        /* Do the auto map */
  53.     }
  54.  
  55. /*
  56. ** get game control flags from joypad
  57. */
  58.     memset(buttonstate,0,sizeof(buttonstate));    /* Zap the buttonstates */
  59.     if (joystick1 & JOYPAD_UP)
  60.          buttonstate[bt_north] = 1;
  61.     if (joystick1 & JOYPAD_DN)
  62.          buttonstate[bt_south] = 1;
  63.     if (joystick1 & JOYPAD_LFT)
  64.          buttonstate[bt_west] = 1;
  65.     if (joystick1 & JOYPAD_RGT)
  66.          buttonstate[bt_east] = 1;
  67.     if (joystick1 & JOYPAD_TL)
  68.          buttonstate[bt_left] = 1;
  69.     if (joystick1 & JOYPAD_TR)
  70.          buttonstate[bt_right] = 1;
  71.     if (joystick1 & JOYPAD_B)
  72.          buttonstate[bt_attack] = 1;
  73.     if (joystick1 & (JOYPAD_Y|JOYPAD_X) )
  74.          buttonstate[bt_run] = 1;
  75.     if (joystick1 & JOYPAD_A)
  76.          buttonstate[bt_use] = 1;
  77.     if (joystick1 & JOYPAD_SELECT) {
  78.          buttonstate[bt_select] = 1;
  79.     }
  80. }
  81.  
  82. /**********************************
  83.  
  84.     Draw the floor and castle #
  85.     
  86. **********************************/
  87.  
  88. void IO_DrawFloor(Word floor)
  89. {
  90.     SetNumber(MapListPtr->InfoArray[floor].ScenarioNum,ScaleX(8),ScaleY(176),1);
  91.     SetNumber(MapListPtr->InfoArray[floor].FloorNum,ScaleX(32),ScaleY(176),1);
  92. }
  93.  
  94. /**********************************
  95.  
  96.     Draw the score
  97.     
  98. **********************************/
  99.  
  100. void IO_DrawScore(LongWord score)
  101. {
  102.     if (!IntermissionHack) {            /* Don't draw during intermission! */
  103.         SetNumber(score,ScaleX(56),ScaleY(176),7);
  104.     }
  105. }
  106.  
  107. /**********************************
  108.  
  109.     Draw the number of live remaining
  110.     
  111. **********************************/
  112.  
  113. void IO_DrawLives(Word lives)
  114. {
  115.     
  116.        if (!IntermissionHack) {            /* Don't draw during intermission! */       
  117.         --lives;            /* Adjust for zero start value */
  118.         if (lives > 9) {
  119.             lives = 9;        /* Failsafe */
  120.         }
  121.         SetNumber(lives,ScaleX(188),ScaleY(176),1);        /* Draw the lives count */
  122.     }
  123. }
  124.  
  125. /**********************************
  126.  
  127.     Draw the health
  128.     
  129. **********************************/
  130.  
  131. void IO_DrawHealth(Word health)
  132. {
  133.     SetNumber(health,ScaleX(210),ScaleY(176),3);
  134. }
  135.  
  136. /**********************************
  137.  
  138.     Draw the ammo remaining
  139.     
  140. **********************************/
  141.  
  142. void IO_DrawAmmo(Word ammo)
  143. {
  144.     SetNumber(ammo,ScaleX(268),ScaleY(176),3);
  145. }
  146.  
  147. /**********************************
  148.  
  149.     Draw the treasure score
  150.     
  151. **********************************/
  152.  
  153. void IO_DrawTreasure(Word treasure)
  154. {
  155.     SetNumber(treasure,ScaleX(128),ScaleY(176),2);
  156. }
  157.  
  158. /**********************************
  159.  
  160.     Draw the keys held
  161.     
  162. **********************************/
  163.  
  164. void IO_DrawKeys(Word keys)
  165. {
  166.     if (keys&1) {
  167.          DrawShape(ScaleX(310),ScaleY(164),GameShapes[10]);
  168.     }
  169.     if (keys&2) {
  170.         DrawShape(ScaleX(310),ScaleY(184),GameShapes[11]);
  171.     }
  172. }
  173.  
  174. /**********************************
  175.  
  176.     Draw the gun in the foreground
  177.     
  178. **********************************/
  179.  
  180. void IO_AttackShape(Word shape)
  181. {
  182.     DrawXMShape(ScaleX(128),ScaleY(96),GameShapes[shape+12]);
  183. }
  184.  
  185. /**********************************
  186.  
  187.     Draw the BJ's face
  188.     
  189. **********************************/
  190.  
  191. void IO_DrawFace(Word face)
  192. {
  193.     DrawShape(ScaleX(160),ScaleY(164),GameShapes[face]);        /* Draw the face */
  194. }
  195.  
  196. /**********************************
  197.  
  198.     Redraw the main status bar
  199.     
  200. **********************************/
  201.  
  202. void IO_DrawStatusBar(void)
  203. {
  204.     DrawShape(ScaleX(0),ScaleY(160),GameShapes[46]);
  205. }
  206.  
  207. /**********************************
  208.  
  209.     Erase the floor and ceiling
  210.     
  211. **********************************/
  212.  
  213. #ifndef __APPLEIIGS__        /* Done in assembly on the IIgs version */
  214. #ifndef __3DO__
  215. void IO_ClearViewBuffer(void)
  216. {
  217.     unsigned char *Screenad;
  218.     Word Count,WCount;
  219.     LongWord *LScreenad;
  220.     LongWord Fill;
  221.  
  222.     Screenad = VideoPointer;
  223.     Count = VIEWHEIGHT/2;
  224.     Fill = 0x2f2f2f2f;
  225.     do {
  226.         WCount = SCREENWIDTH/4;
  227.         LScreenad = (LongWord *) Screenad;
  228.         do {
  229.             *LScreenad++ = Fill;    /* 004 */
  230.         } while (--WCount);
  231.         Screenad+=VideoWidth;
  232.     } while (--Count);
  233.     Count = VIEWHEIGHT/2;
  234.     Fill = 0x2A2A2A2A;
  235.     do {
  236.         WCount = SCREENWIDTH/4;
  237.         LScreenad = (LongWord *) Screenad;
  238.         do {
  239.             *LScreenad++ = Fill;
  240.         } while (--WCount);
  241.         Screenad+=VideoWidth;
  242.     } while (--Count);
  243. }
  244. #endif
  245. #endif
  246.  
  247. /**********************************
  248.  
  249.     Copy the 3-D screen to display memory
  250.     
  251. **********************************/
  252.  
  253. void IO_DisplayViewBuffer (void)
  254. {
  255.     BlastScreen();
  256. /* if this is the first frame rendered, upload everything and fade in */
  257.     if (firstframe) { 
  258.         FadeTo(rGamePal);
  259.         firstframe = 0;
  260.     }
  261. }
  262.